package com.tfw.domain;



import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @program: fruit-sale
 * @description: 优惠
 * @author: Fuwen
 * @create: 2022-07-27 18:11
 **/
public abstract class Preferential extends Entity {
    /**
     * 优惠商品列表码
     */
    private List<String> GoodId;
    /**
     * 起始时间
     */
    private Date beginDate;
    /**
     * 结束时间
     */
    private Date endDate;
    public abstract  BigDecimal useCou(List<Good> good);

    /**
     * 基础计价功能
     * @param goods
     * @return
     */
    public static BigDecimal basePrice(List<Good> goods) {
        int u=0;
        BigDecimal prise=BigDecimal.ZERO;
        for (Good good:goods){
            if (good.getUnitPrice().compareTo(BigDecimal.ZERO)<0||good.getInventory()<0||(u=Weight.getCount(good.getUnit()))<=0){
                throw new IllegalArgumentException("参数错误");
            }
            prise=prise.add(good.getUnitPrice().multiply(BigDecimal.valueOf(good.getInventory())).multiply(BigDecimal.valueOf(u)));
        }
        return prise;
    }

    public List<String> getGoodId() {
        return GoodId;
    }

    public void setGoodId(List<String> goodId) {
        GoodId = goodId;
    }

    public Date getBeginDate() {
        return beginDate;
    }

    public void setBeginDate(Date beginDate) {
        this.beginDate = beginDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
}
